package com.demo.springcloud.service;

import com.demo.springcloud.mapper.AccountMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * @author chenyuan
 * @date 2020/12/24 15:35
 */
@Service
@Slf4j
public class AccountServiceImpl implements AccountService {
	@Resource
	private AccountMapper accountMapper;

	/**
	 * 扣减账户余额
	 */
	@Override
	public int decrease(Long userId, BigDecimal money) {
		log.info("--->>>> account-service中扣减账户余额开始 <<<< ");
		// 暂停几秒，模拟超时异常
		try {
			TimeUnit.SECONDS.sleep(20);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		int decrease = accountMapper.decrease(userId, money);
		log.info("---<<<< account-service中扣减账户余额结束 >>>> ");
		return decrease;
	}
}

